#include "Deque.h"

int main() 
{
	// Populate
	Deque <int> d;
	assert(d.size() == 0);
	for (int i = 0; i < 24; i += 2) 
	{
		d.push_front(i);
		d.push_back(i+1);
	}
	assert(d.size() == 24);
	// Test push
	int nums[] = {22,20,18,16,14,12,10,8,6,4,2,0,1,3,5,7,9,11,13,15,17,19,21,23};
	assert(equal(d.begin(), d.end(), nums));


	// Test pop
	for (int i = 0; i < 6; ++i) 
	{
		d.pop_back();
		d.pop_front();
	}
	assert(d.size() == 12);
	assert(equal(d.begin(), d.end(), nums+6));


	// Test front, back, and at
	assert(d.front() == 10);
	d.front() = 100;
	assert(d.front() == 100);
	assert(d.at(0) == 100);
	assert(d.back() == 11);
	d.back() = 110;
	assert(d.back() == 110);
 	assert(d.at(d.size()-1) == 110);
	assert(d.at(1) == 8);
	d.at(1) = 80;
	assert(d.at(1) == 80);


	// Test boundaries and exceptions
	for (int i = 0; i < 100; ++i) 
	{
		d.pop_back();
		d.pop_front();
	}
	assert(d.size() == 0);
	try 
	{
		d.front();
		assert(0);
	}
	catch (...) 
	{
	}
	try 
	{
		d.back();
		assert(0);
	}
	catch (...) 
	{
	}
	try 
	{
		d.at(0);
		assert(0);
	}
	catch (...) 
	{
	}
	cout << "Tests passed\n";
	system("pause");
	return 0;
}